Trò chơi đua xe động vật trong UNITY Engine
114.729 lượt xem;
- RevivalTask.cs
- GameScreen /
- AnimalRacing /
- Scripts /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 namespace GamePlay
5 {
6 public class RevivalTask : MonoBehaviour
7 {
8 public Sprite[] icons;
9 public GameObject Icon;
10 public GameObject Task;
11
12 private bool isVisible;
13 private float duration;
14 private float stateTime;
15 private float scaleX;
16
17 private bool isRunning;
18
19 public void setIcon(EmotionType emotion)
20 {
21 Icon.GetComponent<SpriteRenderer>().sprite = icons[(int)emotion];
22
23 isRunning = true;
24
25 /*
26 switch (skillType)
27 {
28 case SkillType.BUON:
29 Icon.GetComponent<SpriteRenderer>().sprite = icons[0];
30 break;
31 case SkillType.CUOI:
32 Icon.GetComponent<SpriteRenderer>().sprite = icons[1];
33 break;
34 case SkillType.CUOIDEU:
35 Icon.GetComponent<SpriteRenderer>().sprite = icons[2];
36 break;
37 case SkillType.TUC:
38 Icon.GetComponent<SpriteRenderer>().sprite = icons[3];
39 break;
40 case SkillType.HOAMAT:
41 Icon.GetComponent<SpriteRenderer>().sprite = icons[4];
42 break;
43 }
44 * */
45 }
46
47 public void Update()
48 {
49 if (isVisible && isRunning)
50 {
51 stateTime -= Time.deltaTime;
52 scaleX = stateTime / duration;
53 if (stateTime <= 0)
54 {
55 isVisible = false;
56 scaleX = 0;
57 gameObject.SetActive(false);
58 }
59 Task.transform.localScale = new Vector3(scaleX, 1, 1);
60 }
61 }
62
63 public void show(float duration)
64 {
65 this.duration = duration;
66 this.isVisible = true;
67 this.stateTime = duration;
68 this.scaleX = 1;
69 gameObject.SetActive(true);
70 }
71
72 public void setRunning(bool isRunning)
73 {
74 this.isRunning = isRunning;
75 }
76 }
77 }
2 using System.Collections;
3
4 namespace GamePlay
5 {
6 public class RevivalTask : MonoBehaviour
7 {
8 public Sprite[] icons;
9 public GameObject Icon;
10 public GameObject Task;
11
12 private bool isVisible;
13 private float duration;
14 private float stateTime;
15 private float scaleX;
16
17 private bool isRunning;
18
19 public void setIcon(EmotionType emotion)
20 {
21 Icon.GetComponent<SpriteRenderer>().sprite = icons[(int)emotion];
22
23 isRunning = true;
24
25 /*
26 switch (skillType)
27 {
28 case SkillType.BUON:
29 Icon.GetComponent<SpriteRenderer>().sprite = icons[0];
30 break;
31 case SkillType.CUOI:
32 Icon.GetComponent<SpriteRenderer>().sprite = icons[1];
33 break;
34 case SkillType.CUOIDEU:
35 Icon.GetComponent<SpriteRenderer>().sprite = icons[2];
36 break;
37 case SkillType.TUC:
38 Icon.GetComponent<SpriteRenderer>().sprite = icons[3];
39 break;
40 case SkillType.HOAMAT:
41 Icon.GetComponent<SpriteRenderer>().sprite = icons[4];
42 break;
43 }
44 * */
45 }
46
47 public void Update()
48 {
49 if (isVisible && isRunning)
50 {
51 stateTime -= Time.deltaTime;
52 scaleX = stateTime / duration;
53 if (stateTime <= 0)
54 {
55 isVisible = false;
56 scaleX = 0;
57 gameObject.SetActive(false);
58 }
59 Task.transform.localScale = new Vector3(scaleX, 1, 1);
60 }
61 }
62
63 public void show(float duration)
64 {
65 this.duration = duration;
66 this.isVisible = true;
67 this.stateTime = duration;
68 this.scaleX = 1;
69 gameObject.SetActive(true);
70 }
71
72 public void setRunning(bool isRunning)
73 {
74 this.isRunning = isRunning;
75 }
76 }
77 }